<?php
include($rootPath."classes/mail.php");
$xtpl = new XTemplate($inner_templates."home.contact.htm");
$xtpl_main->assign ("page_title", _LB_CONTACT);
$xtpl->assign ("base_url", $base_url);
$xtpl->assign('txt',stripslashes($text));
//-- get data from static pages
$text = $DB->DBGetField('static_pages', "sp_code = 'contact_us'", 'sp_text');
$xtpl->assign('txt',stripslashes($text));
$name = $DB->DBGetField('static_pages', "sp_code = 'contact_us'", 'sp_name');
$xtpl->assign('name',stripslashes($name));

$action=$_POST['action'];

if($action=="sending"){
	if(md5($_POST['txtcapcha']) == $_SESSION['irv']){
		if($_POST['cbotype']=="other"){	
			$row['type']=$_POST['txttype'];
		}
		else{
			$row['type']=$_POST['cbotype'];
		}
		
		$POST[bc_firstname]=$_POST['txtfirstname'];
		$POST[bc_lastname]=$_POST['txtlastname'];
		$POST[bc_mail]=$_POST['txtemail'];
		$POST[bc_address]=$_POST['txtaddress'];
		$POST[bc_phone]=$_POST['txtphone'];
		$POST[bc_comment]=$_POST['txtdes'];
		$POST[bc_datetime] = date('Y-m-d h:i:s');
		$subject = 'Contact from Customer.';
		
				//var_dump($POST);exit;
		$DB->DBInsert('contact', $POST);

		$sql_dm=mysql_query("SELECT site_email FROM bm_config");
		$row_dm=mysql_fetch_array($sql_dm);
		$mailXtpl = new XTemplate($inner_templates."mail.contact.html");			
                $mailXtpl->assign("item",$_POST);
                $mailXtpl->parse("mail");
                $html_main = $mailXtpl->text("mail");
		//--
		$mail_object = new html_mime_mail("X-Mailer: Html Mime Mail Class");
		$mail_object->add_html($html_main, "");
		$mail_object->set_charset("utf-8", TRUE);
		$mail_object->build_message();
		//-- Function send to mail
		//send($to_name, $to_addr, $from_name, $from_addr, $subject = '', $headers = '')
		$mail_object->send($POST[bc_firstname].'&nbsp;'.$POST[bc_lastname],$row_dm['site_email'],$POST[bc_mail],$POST[bc_mail],'Someone has just sent you an email by contact form!',$subject);	
		
		
		//--
		
		//-- break window
		echo '<script language="javascript">location.href="'.$base_url.'contact/sent"</script>';
                }elseif(md5($_POST['txtcapcha']) != $_SESSION['irv']){
                        echo '<script language="javascript">location.href="'.$base_url.'contact/error"</script>';
                }
                }
                if($_GET['send']=="sent"){
                        $xtpl->assign("msg","Your enquiry has been sent to us. Thank you!");
                }
                elseif($_GET['send']=="error"){
                        $xtpl->assign("msg","Please check the capcha. Thank you!");
                }

//-- end
include $rootPath.'modules/home/left.support_online.php';

?>